package com.leetcode.partition3;

import java.io.*;
import java.util.HashSet;
import java.util.Set;

/**
 * @author `RKC`
 * @date 2022/1/19 8:42
 */
public class LC219存在重复元素II {

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] s = reader.readLine().split("\\s+");
        int[] nums = new int[s.length];
        for (int i = 0; i < s.length; i++) nums[i] = Integer.parseInt(s[i]);
        int k = Integer.parseInt(reader.readLine());
        writer.write(containsNearbyDuplicate(nums, k) + "\n");
        writer.flush();
    }

    public static boolean containsNearbyDuplicate(int[] nums, int k) {
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < nums.length; i++) {
            if (set.contains(nums[i])) return true;
            set.add(nums[i]);
            if (i >= k) set.remove(nums[i - k]);
        }
        return false;
    }
}
